<?php

namespace App\Http\Controllers\Merchant;

use App\Contact;
use App\Http\Response;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ContactController extends Controller
{
    use Response;
    public function index(Request $request)
    {
        $result=Contact::when($request->get('keywords'),function ($query)use ($request){
            $query->where('name','like','%'.$request->get('keywords').'%')
                ->OrWhere('email','like','%'.$request->get('keywords').'%')
                ->OrWhere('comment','like','%'.$request->get('keywords').'%');
        })->latest()->paginate($request->get('pageSize',10),'*','pageNo');
        return $this->success(200,$result);
    }
    public function delete($id)
    {
        $delete=Contact::destroy($id);
        if ($delete){
            return $this->message(200,'delete success');
        }else{
            return $this->message(505,'delete failed');
        }
    }
}
